void Get_L(std::vector<std::vector<double> > &_A, std::vector<std::vector<double> > &_L);
void Get_U(std::vector<std::vector<double> > &_A, std::vector<std::vector<double> > &_U);
void Exchange_Line(std::vector<std::vector<double> > &_A, int _a1, int _a2, int _b1, int _b2);
void Exchange_Row(std::vector<std::vector<double> > &_A, int _a1, int _a2, int _b1, int _b2);
void Plus_Line(std::vector<std::vector<double> > &_A, int _a1, int _a2, int _b1, int _b2, std::vector<std::vector<double> > &_x, int flag);   
     //f = 1, _a1 = _a1 + _a2  
void Plus_Row(std::vector<std::vector<double> > &_A, int _a1, int _a2, int _b1, int _b2, std::vector<std::vector<double> > &_x, int flag);
     //
void Out_A(std::vector<std::vector<double> > &_A);
     //out Matrix
void Out_B(std::vector<double> &_b);
     //out vector
void Out_B_Line(std::vector<double> &_b);
     //out vector in line
void A_T(std::vector<std::vector<double> > &_A);
     //nxn
void A_Copy(std::vector<std::vector<double> > &_A, std::vector<std::vector<double> > &_B);
     //mxn, new B
void b_Copy(std::vector<double> &a, std::vector<double> &b);
     //new b
void AB_To_C(std::vector<std::vector<double> > &A,
             std::vector<std::vector<double> > &B,
             std::vector<std::vector<double> > &C);
     //mxn
void A_To_O(std::vector<std::vector<double> > &A);
     //mxn
void Ab_To_c(std::vector<std::vector<double> > &A,
             std::vector<double> &b,
             std::vector<double> &c);
     //mxn
void ab_To_c(std::vector<double> &a,
             std::vector<double> &b,
             double &c);
     //


void Get_L(std::vector<std::vector<double> > &_A, std::vector<std::vector<double> > &_L)              //
{
    int i, j;
    int n = _A.size();
    for(i = 0; i < n; ++i)
    {
        _L[i][i] = 1;
    }
    for(i = 1; i < n; ++i)
    {
        for(j = 0; j < i; ++j)
        {
            _L[i][j] = _A[i][j];
        }
    }
}

void Get_U(std::vector<std::vector<double> > &_A, std::vector<std::vector<double> > &_U)                    //
{
    int i, j;
    int n = _A.size();
    for(i = 0; i < n; ++i)
    {
        for(j = i; j < n; ++j)
        {
            _U[i][j] = _A[i][j];
        }
    }
}

void Exchange_Line(std::vector<std::vector<double> > &_A, int _a1, int _a2, int _b1, int _b2)                  //
{
    int i;
    double tmp;                         
    for(i = _b1; i <= _b2; ++i)
    {
        tmp = _A[_a1][i];
        _A[_a1][i] = _A[_a2][i];
        _A[_a2][i] = tmp;
    }
}

void Exchange_Row(std::vector<std::vector<double> > &_A, int _a1, int _a2, int _b1, int _b2)                   //
{
    int i;
    double tmp;                         
    for(i = _a1; i <= _a2; ++i)
    {
        tmp = _A[i][_b1];
        _A[i][_b1] = _A[i][_b2];
        _A[i][_b2] = tmp;
    }
}

void Plus_Line(std::vector<std::vector<double> > &_A, int _a1, int _a2, int _b1, int _b2, double _x, int flag)
{
    int i;
    if(flag == 1)
    {
        for(i = _b1; i <= _b2; ++i)
        {
            _A[_a1][i] = _A[_a1][i] + _x * _A[_a2][i];
        }
    }
    else
    {
        for(i = _b1; i <= _b2; ++i)
        {
            _A[_a1][i] = _A[_a1][i] - _x * _A[_a2][i];
        }
    }
}

void Plus_Row(std::vector<std::vector<double> > &_A, int _a1, int _a2, int _b1, int _b2, double _x, int flag)
{
    int i;
    if(flag == 1)
    {
        for(i = _a1; i <= _a2; ++i)
        {
            _A[i][_b1] = _A[i][_b1] + _x * _A[i][_b2];
        }
    }
    else
    {
        for(i = _a1; i <= _a2; ++i)
        {
            _A[i][_b1] = _A[i][_b1] - _x * _A[i][_b2];
        }
    }
}

void Out_A(std::vector<std::vector<double> > &_A)
{
    int m = _A.size();
    int n = _A[0].size();
    for(int i = 0; i < m; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            std::cout << _A[i][j] << " ";
        }
        std::cout << std::endl;
    }
    std::cout << std::endl;
}

void Out_B(std::vector<double> &_b)
{
    int n = _b.size();
    for(int i = 0; i < n; ++i)
    {
        std::cout << _b[i] << std::endl;
    }
    std::cout << std::endl;
}

void Out_B_Line(std::vector<double> &_b)
{
    int n = _b.size();
    for(int i = 0; i < n; ++i)
    {
        std::cout << _b[i] << " ";
    }
    std::cout << std::endl;
}

void A_T(std::vector<std::vector<double> > &_A)
{
    int i, j;
    int n = _A.size();
    double tmp;
    for(i = 0; i < n - 1; ++i)
    {
        for(j = i + 1; j < n; ++j)
        {
            tmp = _A[i][j];
            _A[i][j] = _A[j][i];
            _A[j][i] = tmp;
        }
    }
}

void A_Copy(std::vector<std::vector<double> > &_A, std::vector<std::vector<double> > &_B)
{
    int i, j;
    int n = _A.size();
    for(i = 0; i < n; ++i)
    {
        for(j = 0; j < n; ++j)
        {
            _B[i][j] = _A[i][j];
        }
    }
}

void b_Copy(std::vector<double> &a, std::vector<double> &b)
{
    int i, j, k;
    int n = a.size();
    for(i = 0; i < n; ++i)
    {
        b[i] = a[i];
    }
}

void AB_To_C(std::vector<std::vector<double> > &A,
             std::vector<std::vector<double> > &B,
             std::vector<std::vector<double> > &C)
{
    int i, j, k;
    int m1, m2, m3, n1, n2, n3;

    m1 = A.size();
    n1 = A[0].size();
    m2 = B.size();
    n2 = B[0].size();
    m3 = C.size();
    n3 = C[0].size();
    
    for(i = 0; i < m3; ++i)
    {
        for(j = 0; j < n3; ++j)
        {
            C[i][j] = 0;
            for(k = 0; k < n1; ++k)
            {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }
}

void A_To_O(std::vector<std::vector<double> > &A)
{
    int i, j, k;
    int m, n;
    m = A.size();
    n = A[0].size();
    for(i = 0; i < m; ++i)
    {
        for(j = 0; j < n; ++j)
        {
            A[i][j] = 0;
        }
    }
}

void Ab_To_c(std::vector<std::vector<double> > &A,
             std::vector<double> &b,
             std::vector<double> &c)
{
    int i, j, k;
    int m, n;

    m = A.size();
    n = A[0].size();
        
    for(i = 0; i < m; ++i)
    {
        for(j = 0; j < n; ++j)
        {
            c[i] = 0;
            for(k = 0; k < n; ++k)
            {
                c[i] += A[i][k] * b[k];
            }
        }
    }
}

void ab_To_c(std::vector<double> &a,
             std::vector<double> &b,
             double &c)
{
    int i, j, k;
    int n = a.size();

    c = 0;
    for(i = 0; i < n; ++i)
    {
        c += a[i] * b[i];
    }
}